<template>
  <div class="UserDetail" v-if="userInfo.profile">
    <div class="Top">
      <img v-lazy="userInfo.profile.avatarUrl" alt="" />
      <div class="right">
        <div class="title">
          <span>{{ userInfo.profile.nickname }}</span>
        </div>
        <div class="level">
          <span>LV{{ userInfo.level }}</span>
          <span class="boy" v-if="userInfo.profile.gender == 1">
            <i class="el-icon-user-solid"></i>
          </span>
          <span class="girl" v-if="userInfo.profile.gender == 2">
            <i class="el-icon-user-solid"></i>
          </span>
        </div>
        <div class="Info">
          <div class="card left">
            <div>{{ userInfo.profile.eventCount }}</div>
            <div>动态</div>
          </div>
          <div class="card middle">
            <div>{{ userInfo.profile.follows }}</div>
            <div>关注</div>
          </div>
          <div class="card">
            <div>{{ userInfo.profile.followeds }}</div>
            <div>粉丝</div>
          </div>
        </div>
        <div class="desc">
          <span>个人介绍：</span>
          <span>{{ userInfo.profile.signature }}</span>
        </div>
      </div>
    </div>
    <h4>创建的歌单</h4>
    <MenuList :list="playList" @itemClick="itemClick"></MenuList>
  </div>
</template>

<script>
import MenuList from '@/components/list/MenuList';

export default {
  data() {
    return {
      uid: '',
      userInfo: '',
      playList: '',
    };
  },
  created() {
    this.uid = this.$route.params.uid;
    this.getUserDetail();
    this.getUserPlayList();
  },
  components: { MenuList },
  methods: {
    async getUserDetail() {
      const res = await this.$request('/user/detail', { uid: this.uid });
      this.userInfo = res;
    },
    async getUserPlayList() {
      const { playlist } = await this.$request('/user/playlist', { uid: this.uid });
      this.playList = playlist;
    },
    //歌单点击
    itemClick(id) {
      this.$router.push('/songsmenudetail/' + id);
    },
  },
  watch: {
    '$route.params.uid'(uid) {
      if (!uid) return;
      this.uid = uid;
      this.getUserDetail();
      this.getUserPlayList();
    },
  },
};
</script>

<style scoped='scoped' lang='scss'>
.UserDetail {
  .Top {
    display: flex;
    img {
      @include image(150px, 50%);
      margin-right: 20px;
    }
    .right {
      width: 100%;
      > div {
        margin-bottom: 10px;
      }
      .title {
        span {
          font-size: 22px;
          font-weight: 600;
        }
      }
      .level {
        font-size: 13px;
        border-bottom: solid 1px $gray;
        padding-bottom: 10px;
        :first-child {
          margin-right: 5px;
        }
        .boy {
          color: blue;
        }
        .girl {
          color: pink;
        }
      }
      .Info {
        display: flex;
        text-align: center;
        .card {
          padding: 0 20px;
          :last-child {
            color: #606266;
            font-size: 13px;
          }
        }
        .left {
          padding-left: 0;
        }
        .middle {
          border-left: solid 1px $gray;
          border-right: solid 1px $gray;
        }
      }
      .desc {
        font-size: 12px;
        :last-child {
          color: #606266;
        }
      }
    }
  }
}
</style>